{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Lost In Translation? Multilingual Embedding Models Are All You Need*\n",
    "\n",
    "This notebook by Quynh Nguyen shows how cross-lingual vector search overcomes language barriers, enabling you to query and retrieve information in any language from both single and multilingual datasets. It accompanies the piece *Lost In Translation? Multilingual Embedding Models Are All You Need* from [Elasticsearch Labs](https://www.elastic.co/search-labs)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Prerequisites\n",
    "\n",
    "Before running this notebook, please ensure you have deployed the `.multilingual-e5-small_linux-x86_64` model within the [*Trained Models* view](https://www.elastic.co/docs/explore-analyze/machine-learning/nlp/ml-nlp-deploy-model) as covered in the accompanying article. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Data successfully downloaded and saved to multilingual_coco_sample.json\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import json\n",
    "import urllib3\n",
    "\n",
    "# Disable InsecureRequestWarning\n",
    "urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)\n",
    "\n",
    "### Download multilingual coco dataset\n",
    "### Here we are retrieving first 100 rows for this example\n",
    "### Alternatively, you can use dataset library from Hugging Face\n",
    "url = \"https://datasets-server.huggingface.co/rows?dataset=romrawinjp%2Fmultilingual-coco&config=default&split=restval&offset=0&length=100\"\n",
    "# Make the GET request\n",
    "response = requests.get(url)\n",
    "\n",
    "# Check if the request was successful\n",
    "if response.status_code == 200:\n",
    "    # Parse the JSON response\n",
    "    data = response.json()\n",
    "\n",
    "    # Define the output file path\n",
    "    output_file = \"multilingual_coco_sample.json\"\n",
    "\n",
    "    # Save the JSON data to a file\n",
    "    with open(output_file, \"w\", encoding=\"utf-8\") as f:\n",
    "        json.dump(data, f, indent=4, ensure_ascii=False)\n",
    "\n",
    "    print(f\"Data successfully downloaded and saved to {output_file}\")\n",
    "else:\n",
    "    print(f\"Failed to download data: {response.status_code}\")\n",
    "    print(response.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enter your Elasticsearch credentials:\n"
     ]
    }
   ],
   "source": [
    "from getpass import getpass\n",
    "\n",
    "# Get credentials securely for localhost Elasticsearch\n",
    "print(\"Enter your Elasticsearch credentials:\")\n",
    "elastic_endpoint = input(\"Enter your Elastic endpoint: \")\n",
    "api_key = getpass(\"Enter your API key: \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Successfully connected to Elasticsearch\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/elasticsearch/_sync/client/__init__.py:311: SecurityWarning: Connecting to 'https://localhost:9200' using TLS with verify_certs=False is insecure\n",
      "  _transport = transport_class(\n"
     ]
    }
   ],
   "source": [
    "from elasticsearch import Elasticsearch\n",
    "\n",
    "try:\n",
    "    es = Elasticsearch(\n",
    "        hosts=[elastic_endpoint],\n",
    "        api_key=api_key,\n",
    "        # Disable SSL verification if using localhost\n",
    "        verify_certs=False,\n",
    "    )\n",
    "    es.ping()\n",
    "\n",
    "    print(\"Successfully connected to Elasticsearch\")\n",
    "except Exception as e:\n",
    "    print(f\"Error connecting to Elasticsearch: {e}\")\n",
    "    print(\"Please check your credentials\")\n",
    "    raise"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Before we start, let's do some house keeping. We will create a helper function to prettify the ES response and also set up some constants.\n",
    "\n",
    "You can find the Model ID via 2 ways:\n",
    "1) In Kibana UI, search `Trained Models` to navigate to the list of models\n",
    "2) Via API `GET _ml/trained_models` or via the library wrapper"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'count': 3, 'trained_model_configs': [{'model_id': '.elser_model_2', 'model_type': 'pytorch', 'model_package': {'packaged_model_id': 'elser_model_2', 'model_repository': 'https://ml-models.elastic.co', 'minimum_version': '11.0.0', 'size': 438123914, 'sha256': '2e0450a1c598221a919917cbb05d8672aed6c613c028008fedcd696462c81af0', 'metadata': {}, 'tags': [], 'vocabulary_file': 'elser_model_2.vocab.json'}, 'created_by': 'api_user', 'version': '12.0.0', 'create_time': 1756216912000, 'model_size_bytes': 0, 'estimated_operations': 0, 'license_level': 'platinum', 'description': 'Elastic Learned Sparse EncodeR v2', 'tags': ['elastic'], 'metadata': {}, 'input': {'field_names': ['text_field']}, 'inference_config': {'text_expansion': {'vocabulary': {'index': '.ml-inference-native-000002'}, 'tokenization': {'bert': {'do_lower_case': True, 'with_special_tokens': True, 'max_sequence_length': 512, 'truncate': 'first', 'span': -1}}}}, 'location': {'index': {'name': '.ml-inference-native-000002'}}}, {'model_id': '.multilingual-e5-small', 'model_type': 'pytorch', 'model_package': {'packaged_model_id': 'multilingual-e5-small', 'model_repository': 'https://ml-models.elastic.co', 'minimum_version': '12.0.0', 'size': 470097544, 'sha256': '8e8ac0963a9492e0b03b66bd1d0ad736580a9edcdf7fc012c81fa9260195fe36', 'metadata': {}, 'tags': [], 'vocabulary_file': 'multilingual-e5-small.vocab.json'}, 'created_by': 'api_user', 'version': '12.0.0', 'create_time': 1756219063163, 'model_size_bytes': 0, 'estimated_operations': 0, 'license_level': 'platinum', 'description': 'E5 small multilingual', 'tags': [], 'metadata': {'per_allocation_memory_bytes': 557785256, 'per_deployment_memory_bytes': 470031872}, 'input': {'field_names': ['text_field']}, 'inference_config': {'text_embedding': {'vocabulary': {'index': '.ml-inference-native-000002'}, 'tokenization': {'xlm_roberta': {'do_lower_case': False, 'with_special_tokens': True, 'max_sequence_length': 512, 'truncate': 'first', 'span': -1}}, 'embedding_size': 384}}, 'location': {'index': {'name': '.ml-inference-native-000002'}}, 'prefix_strings': {'ingest': 'passage: ', 'search': 'query: '}}, {'model_id': 'lang_ident_model_1', 'model_type': 'lang_ident', 'created_by': '_xpack', 'version': '7.6.0', 'create_time': 1575548914594, 'model_size_bytes': 1053992, 'estimated_operations': 39629, 'license_level': 'basic', 'description': 'Model used for identifying language from arbitrary input text.', 'tags': ['lang_ident', 'prepackaged'], 'input': {'field_names': ['text']}, 'inference_config': {'classification': {'num_top_classes': 0, 'top_classes_results_field': 'top_classes', 'results_field': 'predicted_value', 'num_top_feature_importance_values': 0, 'prediction_field_type': 'string'}}}]}\n"
     ]
    }
   ],
   "source": [
    "available_models = es.ml.get_trained_models()\n",
    "print(available_models)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Helper function to prettify the ES response\n",
    "prettify_response = lambda response: json.dumps(\n",
    "    response.body.get(\"hits\").get(\"hits\"), indent=2, ensure_ascii=False\n",
    ")\n",
    "# Default E5 model id\n",
    "MODEL_ID = \".multilingual-e5-small\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Successfully bulk indexed 4840 documents\n",
      "Indexing complete!\n"
     ]
    }
   ],
   "source": [
    "# Define the index mapping\n",
    "index_name = \"coco\"\n",
    "mapping = {\n",
    "    \"mappings\": {\n",
    "        \"properties\": {\n",
    "            \"language\": {\"type\": \"keyword\"},\n",
    "            \"description\": {\"type\": \"text\"},\n",
    "            \"en\": {\"type\": \"text\"},\n",
    "            \"image_url\": {\"type\": \"keyword\"},\n",
    "        }\n",
    "    }\n",
    "}\n",
    "\n",
    "# Create the index if it doesn't exist\n",
    "if not es.indices.exists(index=index_name):\n",
    "    es.indices.create(index=index_name, body=mapping)\n",
    "\n",
    "# Load the JSON data\n",
    "with open(\"./multilingual_coco_sample.json\", \"r\") as f:\n",
    "    data = json.load(f)\n",
    "\n",
    "rows = data[\"rows\"]\n",
    "# List of languages to process\n",
    "languages = [\"en\", \"es\", \"de\", \"it\", \"vi\", \"th\"]\n",
    "\n",
    "bulk_data = []\n",
    "for obj in rows:\n",
    "    row = obj[\"row\"]\n",
    "    image_url = row.get(\"image\")\n",
    "    image_url = image_url[\"src\"]\n",
    "\n",
    "    # Process each language\n",
    "    for lang in languages:\n",
    "        # Skip if language not present in this row\n",
    "        if lang not in row:\n",
    "            continue\n",
    "\n",
    "        # Get all descriptions for this language\n",
    "        descriptions = row[lang]\n",
    "        first_eng_caption = row[\"en\"][0]\n",
    "\n",
    "        # Prepare bulk indexing data\n",
    "        for description in descriptions:\n",
    "            if description == \"\":\n",
    "                continue\n",
    "            # Add index operation\n",
    "            bulk_data.append({\"index\": {\"_index\": index_name}})\n",
    "            # Add document\n",
    "            bulk_data.append(\n",
    "                {\n",
    "                    \"language\": lang,\n",
    "                    \"description\": description,\n",
    "                    \"en\": first_eng_caption,\n",
    "                    \"image_url\": image_url,\n",
    "                }\n",
    "            )\n",
    "\n",
    "# Perform bulk indexing\n",
    "if bulk_data:\n",
    "    try:\n",
    "        response = es.bulk(operations=bulk_data)\n",
    "        if response[\"errors\"]:\n",
    "            print(\"Some documents failed to index\")\n",
    "        else:\n",
    "            print(f\"Successfully bulk indexed {len(bulk_data)} documents\")\n",
    "    except Exception as e:\n",
    "        print(f\"Error during bulk indexing: {str(e)}\")\n",
    "\n",
    "print(\"Indexing complete!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we are going to create a pipeline to vectorize the descriptions text_field through our inference text embedding model."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Pipeline 'vectorize_descriptions' created successfully.\n"
     ]
    }
   ],
   "source": [
    "pipeline_body = {\n",
    "    \"description\": \"Pipeline to run the descriptions text_field through our inference text embedding model\",\n",
    "    \"processors\": [\n",
    "        {\"set\": {\"field\": \"temp_desc\", \"value\": \"passage: {{description}}\"}},\n",
    "        {\n",
    "            \"inference\": {\n",
    "                \"field_map\": {\"temp_desc\": \"text_field\"},\n",
    "                \"model_id\": MODEL_ID,\n",
    "                \"target_field\": \"vector_description\",\n",
    "            }\n",
    "        },\n",
    "        {\"remove\": {\"field\": \"temp_desc\"}},\n",
    "    ],\n",
    "}\n",
    "\n",
    "try:\n",
    "    es.ingest.put_pipeline(id=\"vectorize_descriptions\", body=pipeline_body)\n",
    "    print(\"Pipeline 'vectorize_descriptions' created successfully.\")\n",
    "except Exception as e:\n",
    "    print(f\"Error creating pipeline: {str(e)}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We also need to create a new Elasticsearch index with the specified vector mapping."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/var/folders/nj/823bzw2n4xgfktpz5xgr2rpc0000gn/T/ipykernel_74925/1073086454.py:30: DeprecationWarning: Passing transport options in the API method is deprecated. Use 'Elasticsearch.options()' instead.\n",
      "  es.indices.delete(index=\"coco_multilingual\", ignore=[400, 404])\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index 'coco_multilingual' created successfully.\n"
     ]
    }
   ],
   "source": [
    "index_body = {\n",
    "    \"mappings\": {\n",
    "        \"properties\": {\n",
    "            \"description\": {\"type\": \"text\"},\n",
    "            \"en\": {\"type\": \"text\"},\n",
    "            \"image_url\": {\"type\": \"keyword\"},\n",
    "            \"language\": {\"type\": \"keyword\"},\n",
    "            \"vector_description.predicted_value\": {\n",
    "                \"type\": \"dense_vector\",\n",
    "                \"dims\": 384,\n",
    "                \"index\": True,\n",
    "                \"similarity\": \"cosine\",\n",
    "                \"index_options\": {\"type\": \"bbq_hnsw\"},\n",
    "            },\n",
    "        }\n",
    "    }\n",
    "}\n",
    "\n",
    "try:\n",
    "    es.indices.delete(index=\"coco_multilingual\", ignore=[400, 404])\n",
    "    es.indices.create(index=\"coco_multilingual\", body=index_body)\n",
    "    print(\"Index 'coco_multilingual' created successfully.\")\n",
    "except Exception as e:\n",
    "    print(f\"Error creating index: {str(e)}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, we just need to run the pipeline to bring and vectorize the data into the Elasticsearch index."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reindex task started. Task info:\n",
      "{'task': 'vwUBsf4QRcmG-K41mgbung:126018'}\n"
     ]
    }
   ],
   "source": [
    "reindex_body = {\n",
    "    \"source\": {\"index\": \"coco\"},\n",
    "    \"dest\": {\"index\": \"coco_multilingual\", \"pipeline\": \"vectorize_descriptions\"},\n",
    "}\n",
    "\n",
    "response = es.reindex(\n",
    "    body=reindex_body,\n",
    "    # Not waiting for completion here cause this process might take a while\n",
    "    wait_for_completion=False,\n",
    ")\n",
    "\n",
    "print(\"Reindex task started. Task info:\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Voilà, now let's try some queries and have some fun!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"NOa5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.9305427,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Eine Katze, die auf einem Rad eines Fahrzeugs sitzt.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"de\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"qObKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.9305427,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Eine Katze, die auf einem Rad eines Fahrzeugs sitzt.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"de\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"ypQC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.9305427,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Eine Katze, die auf einem Rad eines Fahrzeugs sitzt.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"de\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"UJQS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.9305427,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Eine Katze, die auf einem Rad eines Fahrzeugs sitzt.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"de\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"M-a5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.9274586,\n",
      "    \"_source\": {\n",
      "      \"description\": \"eine Katze mit einem großen flauschigen Schwanz, der auf einem Autoreifen sitzt\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"de\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"p-bKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.9274586,\n",
      "    \"_source\": {\n",
      "      \"description\": \"eine Katze mit einem großen flauschigen Schwanz, der auf einem Autoreifen sitzt\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"de\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"yZQC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.9274586,\n",
      "    \"_source\": {\n",
      "      \"description\": \"eine Katze mit einem großen flauschigen Schwanz, der auf einem Autoreifen sitzt\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"de\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"T5QS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.9274586,\n",
      "    \"_source\": {\n",
      "      \"description\": \"eine Katze mit einem großen flauschigen Schwanz, der auf einem Autoreifen sitzt\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"de\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"L-a5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.92216015,\n",
      "    \"_source\": {\n",
      "      \"description\": \"a cat with a big fluffy tail sitting on top of a car tire \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"o-bKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.92216015,\n",
      "    \"_source\": {\n",
      "      \"description\": \"a cat with a big fluffy tail sitting on top of a car tire \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  }\n",
      "]\n"
     ]
    }
   ],
   "source": [
    "query_body = {\n",
    "    \"size\": 10,\n",
    "    \"_source\": [\"description\", \"language\", \"en\"],\n",
    "    \"knn\": {\n",
    "        \"field\": \"vector_description.predicted_value\",\n",
    "        \"k\": 10,\n",
    "        \"num_candidates\": 100,\n",
    "        \"query_vector_builder\": {\n",
    "            \"text_embedding\": {\"model_id\": MODEL_ID, \"model_text\": \"query: kitty\"}\n",
    "        },\n",
    "    },\n",
    "}\n",
    "\n",
    "response = es.search(index=\"coco_multilingual\", body=query_body)\n",
    "print(prettify_response(response))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"Lua5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.9332434,\n",
      "    \"_source\": {\n",
      "      \"description\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"oubKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.9332434,\n",
      "    \"_source\": {\n",
      "      \"description\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"xJQC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.9332434,\n",
      "    \"_source\": {\n",
      "      \"description\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"SpQS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.9332434,\n",
      "    \"_source\": {\n",
      "      \"description\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"Mea5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.9237063,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A cat hiding in a fender well of a car. \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"pebKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.9237063,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A cat hiding in a fender well of a car. \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"x5QC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.9237063,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A cat hiding in a fender well of a car. \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"TZQS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.9237063,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A cat hiding in a fender well of a car. \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"Mua5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.9234832,\n",
      "    \"_source\": {\n",
      "      \"description\": \"An orange cat hiding on the wheel of a red car.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"pubKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.9234832,\n",
      "    \"_source\": {\n",
      "      \"description\": \"An orange cat hiding on the wheel of a red car.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"yJQC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.9234832,\n",
      "    \"_source\": {\n",
      "      \"description\": \"An orange cat hiding on the wheel of a red car.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"TpQS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.9234832,\n",
      "    \"_source\": {\n",
      "      \"description\": \"An orange cat hiding on the wheel of a red car.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"L-a5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.9205072,\n",
      "    \"_source\": {\n",
      "      \"description\": \"a cat with a big fluffy tail sitting on top of a car tire \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"o-bKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.9205072,\n",
      "    \"_source\": {\n",
      "      \"description\": \"a cat with a big fluffy tail sitting on top of a car tire \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"xZQC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.9205072,\n",
      "    \"_source\": {\n",
      "      \"description\": \"a cat with a big fluffy tail sitting on top of a car tire \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"S5QS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.9205072,\n",
      "    \"_source\": {\n",
      "      \"description\": \"a cat with a big fluffy tail sitting on top of a car tire \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"Oua5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.91670185,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto nascosto in un pozzo parafango di un'auto. \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"rubKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.91670185,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto nascosto in un pozzo parafango di un'auto. \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"0JQC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.91670185,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto nascosto in un pozzo parafango di un'auto. \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"VpQS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.91670185,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto nascosto in un pozzo parafango di un'auto. \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"tea5kpkBDJxtywa-22NY\",\n",
      "    \"_score\": 0.9162387,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A baby lies on blue and green bedding next to a teddy bear.\",\n",
      "      \"en\": \"A baby is laying down with a teddy bear.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"KebKkpkBDJxtywa-822g\",\n",
      "    \"_score\": 0.9162387,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A baby lies on blue and green bedding next to a teddy bear.\",\n",
      "      \"en\": \"A baby is laying down with a teddy bear.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"S5QC5JkBsSOgrYFSA-XZ\",\n",
      "    \"_score\": 0.9162387,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A baby lies on blue and green bedding next to a teddy bear.\",\n",
      "      \"en\": \"A baby is laying down with a teddy bear.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"0ZQS5JkBsSOgrYFSIe43\",\n",
      "    \"_score\": 0.9162387,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A baby lies on blue and green bedding next to a teddy bear.\",\n",
      "      \"en\": \"A baby is laying down with a teddy bear.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"O-a5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.9149751,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto arancione che si nasconde sulla ruota di un'auto rossa.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"r-bKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.9149751,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto arancione che si nasconde sulla ruota di un'auto rossa.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"0ZQC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.9149751,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto arancione che si nasconde sulla ruota di un'auto rossa.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"V5QS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.9149751,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto arancione che si nasconde sulla ruota di un'auto rossa.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"s-a5kpkBDJxtywa-22NY\",\n",
      "    \"_score\": 0.9135839,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A baby wearing gloves, lying next to a teddy bear\",\n",
      "      \"en\": \"A baby is laying down with a teddy bear.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"J-bKkpkBDJxtywa-822g\",\n",
      "    \"_score\": 0.9135839,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A baby wearing gloves, lying next to a teddy bear\",\n",
      "      \"en\": \"A baby is laying down with a teddy bear.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"SZQC5JkBsSOgrYFSA-XZ\",\n",
      "    \"_score\": 0.9135839,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A baby wearing gloves, lying next to a teddy bear\",\n",
      "      \"en\": \"A baby is laying down with a teddy bear.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"z5QS5JkBsSOgrYFSIe43\",\n",
      "    \"_score\": 0.9135839,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A baby wearing gloves, lying next to a teddy bear\",\n",
      "      \"en\": \"A baby is laying down with a teddy bear.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"N-a5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.9131938,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto tabby a strisce arancioni che si snoda sopra la ruota di un veicolo rosso.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"q-bKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.9131938,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto tabby a strisce arancioni che si snoda sopra la ruota di un veicolo rosso.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"zZQC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.9131938,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto tabby a strisce arancioni che si snoda sopra la ruota di un veicolo rosso.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"U5QS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.9131938,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto tabby a strisce arancioni che si snoda sopra la ruota di un veicolo rosso.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"Oea5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.91059595,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto seduto su una ruota di un veicolo.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"rebKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.91059595,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto seduto su una ruota di un veicolo.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"z5QC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.91059595,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto seduto su una ruota di un veicolo.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"VZQS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.91059595,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto seduto su una ruota di un veicolo.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"MOa5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.9097849,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A cat sitting on a wheel of a vehicle.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"pObKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.9097849,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A cat sitting on a wheel of a vehicle.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"xpQC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.9097849,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A cat sitting on a wheel of a vehicle.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"TJQS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.9097849,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A cat sitting on a wheel of a vehicle.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"M-a5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.9096613,\n",
      "    \"_source\": {\n",
      "      \"description\": \"eine Katze mit einem großen flauschigen Schwanz, der auf einem Autoreifen sitzt\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"de\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"p-bKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.9096613,\n",
      "    \"_source\": {\n",
      "      \"description\": \"eine Katze mit einem großen flauschigen Schwanz, der auf einem Autoreifen sitzt\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"de\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"yZQC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.9096613,\n",
      "    \"_source\": {\n",
      "      \"description\": \"eine Katze mit einem großen flauschigen Schwanz, der auf einem Autoreifen sitzt\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"de\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"T5QS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.9096613,\n",
      "    \"_source\": {\n",
      "      \"description\": \"eine Katze mit einem großen flauschigen Schwanz, der auf einem Autoreifen sitzt\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"de\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"sua5kpkBDJxtywa-22NY\",\n",
      "    \"_score\": 0.9091563,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A baby laying in a crib with a stuffed teddy bear.\",\n",
      "      \"en\": \"A baby is laying down with a teddy bear.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"JubKkpkBDJxtywa-822g\",\n",
      "    \"_score\": 0.9091563,\n",
      "    \"_source\": {\n",
      "      \"description\": \"A baby laying in a crib with a stuffed teddy bear.\",\n",
      "      \"en\": \"A baby is laying down with a teddy bear.\",\n",
      "      \"language\": \"en\"\n",
      "    }\n",
      "  }\n",
      "]\n"
     ]
    }
   ],
   "source": [
    "query_body = {\n",
    "    \"size\": 100,\n",
    "    \"_source\": [\"description\", \"language\", \"en\"],\n",
    "    \"knn\": {\n",
    "        \"field\": \"vector_description.predicted_value\",\n",
    "        \"k\": 50,\n",
    "        \"num_candidates\": 1000,\n",
    "        \"query_vector_builder\": {\n",
    "            \"text_embedding\": {\n",
    "                \"model_id\": MODEL_ID,\n",
    "                \"model_text\": \"query: kitty lying on something\",\n",
    "            }\n",
    "        },\n",
    "    },\n",
    "}\n",
    "\n",
    "response = es.search(index=\"coco_multilingual\", body=query_body)\n",
    "print(prettify_response(response))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"C-a5kpkBDJxtywa-22JY\",\n",
      "    \"_score\": 0.9282237,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một cô gái mỉm cười khi cô ấy ôm một con mèo và mặc một chiếc váy màu sắc rực rỡ.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"f-bKkpkBDJxtywa-82ug\",\n",
      "    \"_score\": 0.9282237,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một cô gái mỉm cười khi cô ấy ôm một con mèo và mặc một chiếc váy màu sắc rực rỡ.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"oZQC5JkBsSOgrYFSA-PY\",\n",
      "    \"_score\": 0.9282237,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một cô gái mỉm cười khi cô ấy ôm một con mèo và mặc một chiếc váy màu sắc rực rỡ.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"J5QS5JkBsSOgrYFSIe02\",\n",
      "    \"_score\": 0.9282237,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một cô gái mỉm cười khi cô ấy ôm một con mèo và mặc một chiếc váy màu sắc rực rỡ.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"Cua5kpkBDJxtywa-22JY\",\n",
      "    \"_score\": 0.9268001,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một người phụ nữ trong phòng với một con mèo.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"fubKkpkBDJxtywa-82ug\",\n",
      "    \"_score\": 0.9268001,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một người phụ nữ trong phòng với một con mèo.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"oJQC5JkBsSOgrYFSA-PY\",\n",
      "    \"_score\": 0.9268001,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một người phụ nữ trong phòng với một con mèo.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"JpQS5JkBsSOgrYFSIe02\",\n",
      "    \"_score\": 0.9268001,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một người phụ nữ trong phòng với một con mèo.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"Bua5kpkBDJxtywa-22JY\",\n",
      "    \"_score\": 0.9241804,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Una ragazza sorride mentre tiene in mano un gatto e indossa una gonna dai colori vivaci.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"eubKkpkBDJxtywa-82ug\",\n",
      "    \"_score\": 0.9241804,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Una ragazza sorride mentre tiene in mano un gatto e indossa una gonna dai colori vivaci.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"nJQC5JkBsSOgrYFSA-PY\",\n",
      "    \"_score\": 0.9241804,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Una ragazza sorride mentre tiene in mano un gatto e indossa una gonna dai colori vivaci.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"IpQS5JkBsSOgrYFSIe02\",\n",
      "    \"_score\": 0.9241804,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Una ragazza sorride mentre tiene in mano un gatto e indossa una gonna dai colori vivaci.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"Bea5kpkBDJxtywa-22JY\",\n",
      "    \"_score\": 0.92388994,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Una donna in una stanza con un gatto.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"eebKkpkBDJxtywa-82ug\",\n",
      "    \"_score\": 0.92388994,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Una donna in una stanza con un gatto.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"m5QC5JkBsSOgrYFSA-PY\",\n",
      "    \"_score\": 0.92388994,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Una donna in una stanza con un gatto.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"IZQS5JkBsSOgrYFSIe02\",\n",
      "    \"_score\": 0.92388994,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Una donna in una stanza con un gatto.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"OOa5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.9229232,\n",
      "    \"_source\": {\n",
      "      \"description\": \"un gatto con una grande coda soffice seduto sulla parte superiore di un pneumatico auto \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"rObKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.9229232,\n",
      "    \"_source\": {\n",
      "      \"description\": \"un gatto con una grande coda soffice seduto sulla parte superiore di un pneumatico auto \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"zpQC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.9229232,\n",
      "    \"_source\": {\n",
      "      \"description\": \"un gatto con una grande coda soffice seduto sulla parte superiore di un pneumatico auto \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"VJQS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.9229232,\n",
      "    \"_source\": {\n",
      "      \"description\": \"un gatto con una grande coda soffice seduto sulla parte superiore di un pneumatico auto \",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"QOa5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.9227522,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo màu cam trốn trên vô lăng của một chiếc xe màu đỏ.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"tObKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.9227522,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo màu cam trốn trên vô lăng của một chiếc xe màu đỏ.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"1pQC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.9227522,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo màu cam trốn trên vô lăng của một chiếc xe màu đỏ.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"XJQS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.9227522,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo màu cam trốn trên vô lăng của một chiếc xe màu đỏ.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"0ea5kpkBDJxtywa-22VZ\",\n",
      "    \"_score\": 0.92232275,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo toliet ngồi trên lề đường trước một ngôi nhà.\",\n",
      "      \"en\": \"A large porcelain toilet posed with a tan flower pot. \",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"RebKkpkBDJxtywa-82-h\",\n",
      "    \"_score\": 0.92232275,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo toliet ngồi trên lề đường trước một ngôi nhà.\",\n",
      "      \"en\": \"A large porcelain toilet posed with a tan flower pot. \",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"Z5QC5JkBsSOgrYFSA-fZ\",\n",
      "    \"_score\": 0.92232275,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo toliet ngồi trên lề đường trước một ngôi nhà.\",\n",
      "      \"en\": \"A large porcelain toilet posed with a tan flower pot. \",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"7ZQS5JkBsSOgrYFSIfA3\",\n",
      "    \"_score\": 0.92232275,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo toliet ngồi trên lề đường trước một ngôi nhà.\",\n",
      "      \"en\": \"A large porcelain toilet posed with a tan flower pot. \",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"POa5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.9221459,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo mướp sọc cam nằm trên bánh xe màu đỏ.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"sObKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.9221459,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo mướp sọc cam nằm trên bánh xe màu đỏ.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"0pQC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.9221459,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo mướp sọc cam nằm trên bánh xe màu đỏ.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"WJQS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.9221459,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo mướp sọc cam nằm trên bánh xe màu đỏ.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"Pua5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.921829,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo ngồi trên bánh xe.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"subKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.921829,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo ngồi trên bánh xe.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"1JQC5JkBsSOgrYFSA-ja\",\n",
      "    \"_score\": 0.921829,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo ngồi trên bánh xe.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"WpQS5JkBsSOgrYFSIfI3\",\n",
      "    \"_score\": 0.921829,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một con mèo ngồi trên bánh xe.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"DOa5kpkBDJxtywa-22JY\",\n",
      "    \"_score\": 0.92159337,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một người phụ nữ đang bế một con mèo trong bếp.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"Dua5kpkBDJxtywa-22JY\",\n",
      "    \"_score\": 0.92159337,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một người phụ nữ đang bế một con mèo trong bếp.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"gObKkpkBDJxtywa-82ug\",\n",
      "    \"_score\": 0.92159337,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một người phụ nữ đang bế một con mèo trong bếp.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"gubKkpkBDJxtywa-82ug\",\n",
      "    \"_score\": 0.92159337,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một người phụ nữ đang bế một con mèo trong bếp.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"opQC5JkBsSOgrYFSA-PY\",\n",
      "    \"_score\": 0.92159337,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một người phụ nữ đang bế một con mèo trong bếp.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"pJQC5JkBsSOgrYFSA-PY\",\n",
      "    \"_score\": 0.92159337,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một người phụ nữ đang bế một con mèo trong bếp.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"KJQS5JkBsSOgrYFSIe02\",\n",
      "    \"_score\": 0.92159337,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một người phụ nữ đang bế một con mèo trong bếp.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"KpQS5JkBsSOgrYFSIe02\",\n",
      "    \"_score\": 0.92159337,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Một người phụ nữ đang bế một con mèo trong bếp.\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"vi\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"B-a5kpkBDJxtywa-22JY\",\n",
      "    \"_score\": 0.92153305,\n",
      "    \"_source\": {\n",
      "      \"description\": \"una donna tiene in mano un gatto nella sua cucina\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"e-bKkpkBDJxtywa-82ug\",\n",
      "    \"_score\": 0.92153305,\n",
      "    \"_source\": {\n",
      "      \"description\": \"una donna tiene in mano un gatto nella sua cucina\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"nZQC5JkBsSOgrYFSA-PY\",\n",
      "    \"_score\": 0.92153305,\n",
      "    \"_source\": {\n",
      "      \"description\": \"una donna tiene in mano un gatto nella sua cucina\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"I5QS5JkBsSOgrYFSIe02\",\n",
      "    \"_score\": 0.92153305,\n",
      "    \"_source\": {\n",
      "      \"description\": \"una donna tiene in mano un gatto nella sua cucina\",\n",
      "      \"en\": \"A woman in a room with a cat.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"Oea5kpkBDJxtywa-22dZ\",\n",
      "    \"_score\": 0.9211286,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto seduto su una ruota di un veicolo.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  },\n",
      "  {\n",
      "    \"_index\": \"coco_multilingual\",\n",
      "    \"_id\": \"rebKkpkBDJxtywa-83Ci\",\n",
      "    \"_score\": 0.9211286,\n",
      "    \"_source\": {\n",
      "      \"description\": \"Un gatto seduto su una ruota di un veicolo.\",\n",
      "      \"en\": \"An orange striped tabby cat laying on top of a red vehicle's wheel.\",\n",
      "      \"language\": \"it\"\n",
      "    }\n",
      "  }\n",
      "]\n"
     ]
    }
   ],
   "source": [
    "query_body = {\n",
    "    \"size\": 100,\n",
    "    \"_source\": [\"description\", \"language\", \"en\"],\n",
    "    \"knn\": {\n",
    "        \"field\": \"vector_description.predicted_value\",\n",
    "        \"k\": 50,\n",
    "        \"num_candidates\": 1000,\n",
    "        \"query_vector_builder\": {\n",
    "            \"text_embedding\": {\"model_id\": MODEL_ID, \"model_text\": \"query: 고양이\"}\n",
    "        },\n",
    "    },\n",
    "}\n",
    "\n",
    "response = es.search(index=\"coco_multilingual\", body=query_body)\n",
    "print(prettify_response(response))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
